﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.UI
{
    /// <summary>
    /// 预加载管理器
    /// </summary>
    public static class PreloadManager
    {
        public static List<PreloadInfo> InfoList = new List<PreloadInfo>();

        public static PreloadInfo Get(string scene, string part)
        {
            for (int index = 0; index < InfoList.Count; index++)
            {
                PreloadInfo pro = InfoList[index];
                if(string.Equals(pro.Scene, scene, StringComparison.CurrentCultureIgnoreCase)
                    && string.Equals(pro.Part, part, StringComparison.CurrentCultureIgnoreCase))
                {
                    return pro;
                }
            }
            return null;
        }

        public static void Save(string scene, string part, IPreloader preloader)
        {
            PreloadInfo pro = new PreloadInfo(scene, part, preloader);
            InfoList.Add(pro);
        }

        public static void Clear()
        {
            InfoList.Clear();
        }

        /// <summary>
        /// 启动的外部程序信息
        /// </summary>
        public class PreloadInfo
        {
            public string Scene { get; private set; }
            public string Part { get; private set; }

            public IPreloader Preloader { get; private set; }

            public PreloadInfo(string scene, string part, IPreloader preloader)
            {
                Scene = scene;
                Part = part;
                Preloader = preloader;
            }
        }
    }

}
